from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-25 14:11:38.758670
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 25, Feb, 2021
Time: 14:11:44
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4085
Nobs: 213.000 HQIC: -47.2548
Log likelihood: 2463.66 FPE: 1.69233e-21
AIC: -47.8288 Det(Omega_mle): 1.11984e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.470008 0.136591 3.441 0.001
L1.Burgenland 0.072796 0.069969 1.040 0.298
L1.Kärnten -0.217810 0.059451 -3.664 0.000
L1.Niederösterreich 0.132196 0.160242 0.825 0.409
L1.Oberösterreich 0.254581 0.142323 1.789 0.074
L1.Salzburg 0.215663 0.075584 2.853 0.004
L1.Steiermark 0.098319 0.102146 0.963 0.336
L1.Tirol 0.130345 0.068201 1.911 0.056
L1.Vorarlberg -0.013889 0.061860 -0.225 0.822
L1.Wien -0.127067 0.133669 -0.951 0.342
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477291 0.164217 2.906 0.004
L1.Burgenland 0.010321 0.084121 0.123 0.902
L1.Kärnten 0.352677 0.071475 4.934 0.000
L1.Niederösterreich 0.107305 0.192652 0.557 0.578
L1.Oberösterreich -0.128970 0.171108 -0.754 0.451
L1.Salzburg 0.198892 0.090871 2.189 0.029
L1.Steiermark 0.202906 0.122805 1.652 0.098
L1.Tirol 0.141198 0.081995 1.722 0.085
L1.Vorarlberg 0.156732 0.074372 2.107 0.035
L1.Wien -0.505210 0.160704 -3.144 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.313883 0.062389 5.031 0.000
L1.Burgenland 0.100118 0.031959 3.133 0.002
L1.Kärnten -0.018119 0.027155 -0.667 0.505
L1.Niederösterreich 0.096588 0.073192 1.320 0.187
L1.Oberösterreich 0.306141 0.065008 4.709 0.000
L1.Salzburg 0.000770 0.034524 0.022 0.982
L1.Steiermark -0.016273 0.046656 -0.349 0.727
L1.Tirol 0.078285 0.031152 2.513 0.012
L1.Vorarlberg 0.101259 0.028255 3.584 0.000
L1.Wien 0.044176 0.061055 0.724 0.469
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220045 0.068411 3.217 0.001
L1.Burgenland -0.004218 0.035044 -0.120 0.904
L1.Kärnten 0.020320 0.029776 0.682 0.495
L1.Niederösterreich 0.043210 0.080257 0.538 0.590
L1.Oberösterreich 0.386605 0.071282 5.424 0.000
L1.Salzburg 0.086778 0.037856 2.292 0.022
L1.Steiermark 0.179197 0.051159 3.503 0.000
L1.Tirol 0.039895 0.034158 1.168 0.243
L1.Vorarlberg 0.086871 0.030983 2.804 0.005
L1.Wien -0.059595 0.066948 -0.890 0.373
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.513908 0.135962 3.780 0.000
L1.Burgenland 0.061446 0.069647 0.882 0.378
L1.Kärnten 0.015947 0.059177 0.269 0.788
L1.Niederösterreich -0.015892 0.159504 -0.100 0.921
L1.Oberösterreich 0.136760 0.141668 0.965 0.334
L1.Salzburg 0.060351 0.075236 0.802 0.422
L1.Steiermark 0.122569 0.101675 1.205 0.228
L1.Tirol 0.210732 0.067887 3.104 0.002
L1.Vorarlberg 0.024210 0.061576 0.393 0.694
L1.Wien -0.120591 0.133053 -0.906 0.365
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185120 0.096886 1.911 0.056
L1.Burgenland -0.019326 0.049630 -0.389 0.697
L1.Kärnten -0.007057 0.042169 -0.167 0.867
L1.Niederösterreich 0.081390 0.113662 0.716 0.474
L1.Oberösterreich 0.406569 0.100952 4.027 0.000
L1.Salzburg -0.018127 0.053613 -0.338 0.735
L1.Steiermark -0.018009 0.072453 -0.249 0.804
L1.Tirol 0.180355 0.048376 3.728 0.000
L1.Vorarlberg 0.045687 0.043879 1.041 0.298
L1.Wien 0.171056 0.094813 1.804 0.071
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.247648 0.126596 1.956 0.050
L1.Burgenland 0.049093 0.064850 0.757 0.449
L1.Kärnten -0.034942 0.055101 -0.634 0.526
L1.Niederösterreich -0.025290 0.148517 -0.170 0.865
L1.Oberösterreich -0.075655 0.131909 -0.574 0.566
L1.Salzburg 0.052928 0.070054 0.756 0.450
L1.Steiermark 0.393432 0.094672 4.156 0.000
L1.Tirol 0.463789 0.063211 7.337 0.000
L1.Vorarlberg 0.160629 0.057334 2.802 0.005
L1.Wien -0.229584 0.123888 -1.853 0.064
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125750 0.152017 0.827 0.408
L1.Burgenland 0.021736 0.077872 0.279 0.780
L1.Kärnten -0.071355 0.066165 -1.078 0.281
L1.Niederösterreich 0.198255 0.178340 1.112 0.266
L1.Oberösterreich -0.009183 0.158397 -0.058 0.954
L1.Salzburg 0.253601 0.084121 3.015 0.003
L1.Steiermark 0.138085 0.113682 1.215 0.224
L1.Tirol 0.050057 0.075904 0.659 0.510
L1.Vorarlberg 0.065717 0.068847 0.955 0.340
L1.Wien 0.230746 0.148765 1.551 0.121
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.576128 0.081326 7.084 0.000
L1.Burgenland -0.035959 0.041660 -0.863 0.388
L1.Kärnten -0.013373 0.035397 -0.378 0.706
L1.Niederösterreich 0.001349 0.095408 0.014 0.989
L1.Oberösterreich 0.295599 0.084739 3.488 0.000
L1.Salzburg 0.018093 0.045003 0.402 0.688
L1.Steiermark 0.004160 0.060817 0.068 0.945
L1.Tirol 0.077003 0.040607 1.896 0.058
L1.Vorarlberg 0.119375 0.036832 3.241 0.001
L1.Wien -0.035542 0.079586 -0.447 0.655
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.136877 0.048221 0.198359 0.248911 0.069021 0.128923 -0.038151 0.170315
Kärnten 0.136877 1.000000 0.004335 0.193999 0.165362 -0.118731 0.148123 0.008961 0.315382
Niederösterreich 0.048221 0.004335 1.000000 0.285673 0.077094 0.224419 0.149380 0.046324 0.366775
Oberösterreich 0.198359 0.193999 0.285673 1.000000 0.294318 0.285547 0.103391 0.069561 0.131949
Salzburg 0.248911 0.165362 0.077094 0.294318 1.000000 0.145819 0.055261 0.087177 -0.011164
Steiermark 0.069021 -0.118731 0.224419 0.285547 0.145819 1.000000 0.116845 0.119628 -0.104670
Tirol 0.128923 0.148123 0.149380 0.103391 0.055261 0.116845 1.000000 0.181614 0.161921
Vorarlberg -0.038151 0.008961 0.046324 0.069561 0.087177 0.119628 0.181614 1.000000 0.024835
Wien 0.170315 0.315382 0.366775 0.131949 -0.011164 -0.104670 0.161921 0.024835 1.000000